﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class denglu : Form
    {
        public denglu()
        {
            InitializeComponent();
        }
        Bestdao dao = new Bestdao();
        private void button1_Click(object sender, EventArgs e)
        {
            //先对记住密码的属性进行判断，看用户是否选中了记住密码
            if (checkBox1.Checked == true)
            {
                //如果记住密码被选中，就将账号的记住密码改为是
                string zhao = string.Format("update admin_info set admin_type='{0}' where admin_name='{1}'","是",textBox1.Text);
                dao.query(zhao);
                //再判断用户输入的账号密码是否正确
                string sql = string.Format("select count(1) from admin_info where admin_pwd={0} and admin_name='{1}'", textBox2.Text, textBox1.Text);
                int he = dao.scalar(sql);
                if (he != 0)
                {
                    //如果用户账号密码正确就提示登陆成功
                    MessageBox.Show("登陆成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Form1 yi = new Form1();
                    this.Hide();
                    yi.Show();
                }
                else
                {
                    //否则就提示登陆失败
                    MessageBox.Show("账号或者密码错误", "提示");
                }
            }
            else
            {
                //如果没有勾选记住密码就将账号的记住密码改为否
                string gai = string.Format("update admin_info set admin_type='{0}' where admin_name='{1}'", "否", textBox1.Text);
                dao.query(gai);
                //然后再对用户输入的账号密码进行判断
                string sql = string.Format("select count(1) from admin_info where admin_pwd={0} and admin_name='{1}'", textBox2.Text, textBox1.Text);
                int he = dao.scalar(sql);
                if (he != 0)
                {
                    //如果账号是对的话，就登陆成功
                    MessageBox.Show("登陆成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Form1 yi = new Form1();
                    this.Hide();
                    yi.Show();
                }
                else
                {
                    //否则就提示登陆失败
                    MessageBox.Show("账号或者密码错误", "提示");
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //点击取消之后就关闭程序
            MessageBox.Show("程序关闭","提示");
            Application.Exit();
        }

        private void denglu_Load(object sender, EventArgs e)
        {
            //判断是否有账户记住账号密码
            string sql = "select top 1 admin_pwd from admin_info where admin_type='是'";
            string deng = dao.Scal(sql);
            if (deng!=null)
            {
                //如果有被记录账号的就返回这个账号并填充到账号框中
                textBox2.Text = deng;
            }
            //判断是否有账户记住账号密码
            string cha = "select top 1 admin_name from admin_info where admin_type='是'";
            string lu = dao.Scal(cha);
            if (lu!=null)
            {
                //如果有被记录账号的就返回这个账号并填充到密码框中
                textBox1.Text = lu;
            }
            //如果有用户账号被记住就将记住密码改为默认选中
            checkBox1.Checked = true;
        }
    }
}
